

package ru.samgtu.wst.ui.swing;

import java.util.regex.Pattern;

import ru.samgtu.wst.model.ConversationID;
import ru.samgtu.wst.model.ConversationModel;
import ru.samgtu.wst.model.FilteredConversationModel;
import ru.samgtu.wst.model.FrameworkModel;
import ru.samgtu.wst.model.HttpUrl;


public class ImageFilteredConversationModel extends FilteredConversationModel {

	private ConversationModel _model;
	private Pattern pattern = Pattern
			.compile("^.*\\.(gif|jpg|png|axd\\?.*|style)$");
	private boolean filterImages = true;

	/** Creates a new instance of UrlFilteredConversationModel */
	public ImageFilteredConversationModel(FrameworkModel model,
			ConversationModel cmodel) {
		super(model, cmodel);
		_model = cmodel;
	}

	public void setFilterImages(boolean filter) {
		if (filter != filterImages) {
			filterImages = filter;
			updateConversations();
		}
	}

	public boolean getFilterImages() {
		return filterImages;
	}

	@Override
	public boolean shouldFilter(ConversationID id) {
		if (!filterImages) {
			return false;
		} else {
			HttpUrl url = _model.getRequestUrl(id);
			boolean result = pattern.matcher(url.toString()).matches();
			System.out.println("Result for " + url + " : " + result);
			return result;
		}
	}

}
